//
//  AlarmTableViewCell.m
//  JiuLe
//
//  Created by xcq on 15/11/10.
//  Copyright © 2015年 Fine. All rights reserved.
//
#import "ConfigDefine.h"
#import "AlarmTableViewCell.h"
#import "UserDataMarco.h"
#import "JLClockModel.h"
@interface AlarmTableViewCell ()
/** 开关 */
@property (weak, nonatomic) IBOutlet UIButton *switches;
/** 设置按钮 */
@property (weak, nonatomic) IBOutlet UIButton *setting;
/** 闹钟时间 */
@property (weak, nonatomic) IBOutlet UILabel *alarmTime;
/** 闹钟事件 */
@property (weak, nonatomic) IBOutlet UILabel *alarmEvent;
@end

@implementation AlarmTableViewCell

- (void)awakeFromNib {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
        [self setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
        [self setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    [_setting addTarget:self
                 action:@selector(settingEvent:)
       forControlEvents:UIControlEventTouchUpInside];
}
- (IBAction)onOrOffEvent:(id)sender {
    UIButton *btn = (UIButton *)sender;
    btn.selected = !btn.selected;
    _model.is_set = [NSString stringWithFormat:@"%d",btn.selected];
    
//    if (self.tag == 0) {
//        [NSUserDefaults setUserObject:_model forKey:UserDataAlarmArraysOne];
//    } else if (self.tag == 1) {
//        [NSUserDefaults setUserObject:_model forKey:UserDataAlarmArraysTwo];
//    } else if (self.tag == 2) {
//        [NSUserDefaults setUserObject:_model forKey:UserDataAlarmArraysThree];
//    }
    _callBack(1,_model,(int)self.tag);
}

- (IBAction)goSetting:(id)sender {
    _callBack(0,_model,(int)self.tag);
}

- (void)settingEvent:(UIButton *)btn {
    _callBack(0,_model,(int)self.tag);
}

- (void)setModel:(JLClockModel *)model {
    if (model==nil) {
        return;
    }
    _model = model;
    _switches.selected = [_model.is_set boolValue];
    if ([[_model type] isEqualToString:@"1"]) {
        _alarmEvent.text = @"跑步";
    } else if ([[_model type] isEqualToString:@"2"]) {
        _alarmEvent.text = @"吃药";
    } else {
        _alarmEvent.text = @"睡觉";
    }
    
    
    _alarmTime.text = [[[_model.clock substringWithRange:NSMakeRange(0, 2)] stringByAppendingString:@":"]stringByAppendingString:[_model.clock substringWithRange:NSMakeRange(2, 2)]];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
